<?php 
/*
 module:		车队管理控制器
 create_time:	2021-07-27 19:08:33
 author:		
 contact:		
*/

namespace app\admin\controller;
use think\exception\ValidateException;
use app\admin\model\User as UserModel;
use think\facade\Db;

class User extends Admin {

    public function getList()
    {
        $limit  = $this->request->post('limit', 20, 'intval');
        $page = $this->request->post('page', 1, 'intval');
        $mobile = $this->request->post('mobile');
        $userInfo = $this->userInfo;
        $where = [
            'main_user_id' => $userInfo['main_user_id'],
            'is_delete' => 0
        ];
        $field = 'id,main_user_id,nickname,mobile,avatar,name,wechat_bind,remark,status,
        FROM_UNIXTIME(last_login_time, "%Y-%m-%d %H:%i") last_login_time,last_login_ip,
        FROM_UNIXTIME(create_time, "%Y-%m-%d %H:%i") create_time';
        if (!empty($mobile)) {
            $where = [
                'mobile' => $mobile
            ];
        }
        $res = UserModel::where($where)
            ->field($field)
            ->order('id desc')
            ->paginate(['list_rows'=>$limit,'page'=>$page])
            ->toArray();
        $data = [
            'code' => 200,
            'data' => $res
        ];
        return json($data);
    }


    public function getBasicInfo()
    {
        $data = [
            'code' => 200,
            'data' => [
                'user_info' => [
                    'nickname' => $this->userInfo['nickname'],
                    'mobile' => $this->userInfo['mobile'],
                    'avatar' => $this->userInfo['avatar'],
                    'name' => $this->userInfo['name'],
                    'remark' => $this->userInfo['remark'],
                ]
            ]
        ];
        return json($data);
    }
}

